package com.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;


@Configuration
@EnableWebSocketMessageBroker
public class WebSocketMessageConfig extends AbstractWebSocketMessageBrokerConfigurer {
  
	
	@Override
	public void configureMessageBroker(MessageBrokerRegistry config) {
		config.enableSimpleBroker("/topic");  ////设置服务器广播消息的基础路径
		config.setApplicationDestinationPrefixes("/app");// //设置客户端订阅消息的基础路径
		config.setUserDestinationPrefix("/user"); //这句表示给指定用户发送（一对一）的主题前缀是“/user/”
		//config.setPathMatcher(new AntPathMatcher("."));    //可以已“.”来分割路径，看看类级别的@messageMapping和方法级别的@messageMapping
	}

	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) {
		//hello就是websocket的端点，客户端需要注册这个端点进行链接，withSockJS允许客户端利用sockjs进行浏览器兼容性处理
		registry.addEndpoint("/hello").withSockJS();
	}
	

     
	/**
	 * 
	 * 客户端流输入配置
	 * 
	 * 
	 */
	@Override
	public void configureClientInboundChannel(ChannelRegistration registration) {
		// TODO Auto-generated method stub
		super.configureClientInboundChannel(registration);
	}
    
	/**
	 * 客户端流输出配置
	 * 
	 * 
	 */
	@Override
	public void configureClientOutboundChannel(ChannelRegistration registration) {
		// TODO Auto-generated method stub
		super.configureClientOutboundChannel(registration);
	}
	
	
	
	

}